function init(){
    setReadMessage();
}

function setReadMessage(){
    $('.btn-contact-read').click(function(e){
        var index = $(this).attr('data-index');
        var parent_row = $("#row" + index);
        var remote_url = $(this).attr('href');
        e.preventDefault();
        $('#modal-contact-detail').modal({
            remote: remote_url
        });
        var chk_unread = parent_row.find('#chk' + index);
        if(chk_unread.is(':checked')){
            chk_unread.prop('checked', false).change();
        }
        return false;
    });

    $('.input-contact-unread, .input-contact-delete-flg').change(function(){
        var url = $(this).parents('table').attr('data-href');
        var value = $(this).is(':checked')==true?1:0;
        var name = $(this).attr('data-name');
        var contact = {id: $(this).parents('tr').attr('data-id')};
        contact[name] = value;
        changeState(url, {contact: contact});

        var index = $(this).attr('data-index');
        var parent_row = $("#row" + index);
        if($(this).hasClass('input-contact-delete-flg')){
            parent_row.slideUp();
        } else {
            setUnreadMessage(parent_row, index);
        }
    });
}

function setUnreadMessage(parent_row, index){
    parent_row.find('span.unread').removeClass('unread');
}